<%@ page pageEncoding = "UTF-8"%>
<%!
  Message searchNews(Input input) {
    Message msg = new Message();
	Integer page = 1; // 页码
	Integer itemCount = input.getInt("item_count", 20); // 每一页条目
    String category = input.getDesc("category", ""); // 新闻类别
    String keywords = input.getDesc("keywords", ""); // 关键字
    Integer hospital = input.getInt("hospital", -1); // 医院编号
    Integer uuid = input.getInt("uid", -1);
	String sinceID = input.getDesc("since_id","0"); // 下拉刷新
	String maxID = input.getDesc("max_id","0"); // 上拉加载
	String newsId = "";
    String selectContent = "new map(n.id as id , n.newsId as news_id, n.url as url, n.title as title, n.summary as summary, n.time as time, n.img as img, n.jsonString as json, n.tag as tag, n.category as category, n.branchName as branch_name)";
    Where where = new Where();
	String order = "desc"; // 排序
    if (!"".equals(category)) {
      where.and("n.category=", category);
    }
	if (!sinceID.equals("0")) {
		where.and("n.newsId > " + sinceID);
		order = "asc";
	} else if (!maxID.equals("0")) {
		where.and("n.newsId < " + maxID);
	}
    List newsList = QBuilder.db("basedb").select(selectContent).from("News n").where(where.and("n.hospital=", hospital).and("n.status = ", STATUS_ENABLE).and("n.title like '%" + keywords + "%' or n.summary like '%" + keywords + "%' or n.content like'%" + keywords + "%'")).order("n.newsId", order).page(itemCount, page).query().getResultObj();
    if (newsList.size() == 0) {
      msg = new Message(30091, "暂无相关数据");
    }
    OperateHistory oh = new OperateHistory();
    oh.setHospital(hospital);
    oh.setCategory(NEWS_CATEGORY);
    oh.setOperate(LOVE);
    msg.put("data", love(query(newsList, oh), uuid, oh));
    return msg;
  }
%>